package hot100;

public class Solution470 {

    public int badRand10() {
        int sum = 0;
        for (int i = 0; i < 10; i++) {
            sum += rand7();
        }
        return sum % 10 + 1;
    }

    public int refusedRand10() {
        int index = 0;
        do {
            int rand1 = rand7();
            int rand2 = rand7();
            index = rand1 + (rand2 - 1) * 7;
        } while (index > 40);
        return index % 10 + 1;
    }

    public int rand10() {
        while (true) {
            int a = rand7();
            int b = rand7();
            int index = a + (b - 1) * 7;
            if (index < 40) {
                return index % 10 + 1;
            }
            index -= 40;
            b = rand7();
            index = index + (b - 1) * 7;
            if (index < 60) {
                return index % 10 + 1;
            }
            index -= 60;
            b = rand7();
            index = index + (b - 1) * 7;
            if (index < 20) {
                return index % 10 + 1;
            }
        }
    }

    private int rand7() {
        return 0;
    }
}
